<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="generator" content="MATLAB R2016a"><meta http-equiv="X-UA-Compatible" content="IE=edge,IE=9,chrome=1"><title>实用计算方法实验三——龙格库塔法解一阶常微分方程</title><style type="text/css">
* {margin: 0; padding: 0;}
body {text-align: start; line-height: 17.2339992523193px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Consolas, Inconsolata, Menlo, monospace; font-style: normal; font-size: 14px; font-weight: normal; text-decoration: none; white-space: normal; }
h1, h2 {font-weight: normal;}
.content { padding: 30px; }

.S0 { margin-left: 0px; margin-top: 0px; margin-bottom: 0px; margin-right: 0px;  }
.S1 { line-height: 26.3999996185303px; min-height: 24px; white-space: pre-wrap; color: rgb(213, 80, 0); font-family: Helvetica, Arial, sans-serif; font-size: 22.0000019073486px; white-space: pre-wrap; margin-left: 4px; margin-top: 3px; margin-bottom: 15px; margin-right: 10px;  }
.S2 { min-height: 0px; margin-left: 0px; margin-top: 0px; margin-bottom: 0px; margin-right: 0px;  }
.S3 { line-height: 21px; min-height: 17px; white-space: pre-wrap; font-family: Helvetica, Arial, sans-serif; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px;  }
.S4 { margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px;  }
.S5 { line-height: 15.5926666259766px; min-height: 18px; white-space: nowrap; font-size: 12.6666669845581px; white-space: nowrap; margin-left: 0px; margin-top: 0px; margin-bottom: 0px; margin-right: 0px;  }
.S6 { line-height: 15.5926675796509px; min-height: 0px; white-space: pre; color: rgb(34, 139, 34); font-size: 12.6666679382324px; white-space: pre; margin-left: 0px; margin-top: 0px; margin-bottom: 0px; margin-right: 45px;  }
.S7 { line-height: 15.5926675796509px; min-height: 0px; white-space: pre; font-size: 12.6666679382324px; white-space: pre; margin-left: 0px; margin-top: 0px; margin-bottom: 0px; margin-right: 45px;  }
.S8 { line-height: 15.5926675796509px; min-height: 0px; white-space: pre; font-size: 12.6666679382324px; white-space: pre; margin-left: 0px; margin-top: 0px; margin-bottom: 0px; margin-right: 0px;  }
.S9 { line-height: 15.5926675796509px; min-height: 0px; white-space: pre; color: rgb(160, 32, 240); font-size: 12.6666679382324px; white-space: pre; margin-left: 0px; margin-top: 0px; margin-bottom: 0px; margin-right: 0px;  }
.S10 { line-height: 15.5926675796509px; min-height: 0px; white-space: pre; color: rgb(0, 0, 255); font-size: 12.6666679382324px; white-space: pre; margin-left: 0px; margin-top: 0px; margin-bottom: 0px; margin-right: 0px;  }
.S11 { line-height: 15.5926675796509px; min-height: 0px; white-space: pre; color: rgb(0, 0, 255); font-size: 12.6666679382324px; white-space: pre; margin-left: 0px; margin-top: 0px; margin-bottom: 0px; margin-right: 45px;  }
.S12 { line-height: 21px; min-height: 17px; white-space: pre-wrap; font-family: Helvetica, Arial, sans-serif; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px;  }
.S13 { margin-left: 3px; margin-top: 10px; margin-bottom: 4px; margin-right: 3px;  }
.S14 { line-height: 15.5926675796509px; min-height: 0px; white-space: pre; color: rgb(160, 32, 240); font-size: 12.6666679382324px; white-space: pre; margin-left: 0px; margin-top: 0px; margin-bottom: 0px; margin-right: 45px;  }
.S15 { color: rgb(64, 64, 64); margin-left: 0px; margin-top: 0px; margin-bottom: 0px; margin-right: 0px;  }

.LineNodeBlock {margin: 10px 0 10px 0;}
.LineNodeBlock+.paragraphNode {margin-top: 10px;}
.lineNode {padding-left: 10px; background-color: #F7F7F7; border-left: 1px solid #E9E9E9; border-right: 1px solid #E9E9E9;}
.inlineWrapper:first-child .lineNode,.inlineWrapper.outputs+.inlineWrapper .lineNode {padding-top: 5px; border-top: 1px solid #E9E9E9;}
.inlineWrapper:last-child .lineNode,.inlineWrapper.outputs .lineNode {padding-bottom: 5px; border-bottom: 1px solid #E9E9E9;}
.lineNode .textBox {white-space: pre;}
.outputGroup {margin: 2px 0 2px 0; padding: 2px 2px 2px 4px;}
.outputRegion {}
.outputParagraph {color: rgba(64, 64, 64, 1); padding: 10px 0 6px 17px; background: white; overflow-x: hidden;}
.inlineWrapper:last-child .outputParagraph {border-bottom-left-radius: 4px; border-bottom-right-radius: 4px;}
.outputParagraph:empty {margin: 0;}
.inlineElement .symbolicElement {}
.embeddedOutputsSymbolicElement .MathEquation {margin-top: 5px; margin-bottom: 5px;}
.embeddedOutputsSymbolicElement .MathEquation.displaySymbolicElement {margin-left: 15px;}
.embeddedOutputsSymbolicElement .MathEquation.inlineSymbolicElement {margin-left: 5px;}
.embeddedOutputsSymbolicElement {overflow-x: auto; overflow-y: hidden;}
.embeddedOutputsSymbolicElement { overflow: initial !important;}
.embeddedOutputsTextElement,.embeddedOutputsVariableStringElement {font-family: Consolas, Inconsolata, Menlo, monospace; font-size: 12px; white-space: pre; word-wrap: initial; min-height: 18px; max-height: 250px; overflow: auto;}
.textElement {padding-top: 3px;}
.embeddedOutputsTextElement.inlineElement {}
.inlineElement .textElement {}
.embeddedOutputsTextElement,.embeddedOutputsVariableStringElement { max-height: none !important; overflow: initial !important;}
.veSpecifier {}
.veContainer {}
.veSpecifierBox {height: 400px; width: 500px;}
.veSpecifier .veTable {padding-top: 3px; padding-bottom: 4px;}
.veSpecifierBox .veSpecifier .veContainer {position: relative; width: 100%; height: 370px;}
.veSpecifierBox .dijitDialogPaneContent {width: 97% !important; height: 88% !important;}
.veSpecifier .veTable .rowHeadersWrapper {padding-bottom: 0;}
.veSpecifier .veTable .scroller .variableEditorRenderers {padding-right: 3px; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none;}
.veVariableValueSummary {display: inline-block;}
.veSpecifier .veTable .topHeaderWrapper,.veSpecifier .veTable .bottomRowHeaderWrapper {visibility: hidden; z-index: 0;}
.veMetaSummary {font-style: italic;}
.veSpecifier .veTable .scroller {overflow: hidden;}
.veSpecifier .veTable:hover .scroller {overflow: auto;}
.veSpecifier .veVariableName,.veSpecifier .veDimensionFont {font-family: Consolas, Inconsolata, Menlo, monospace; font-size: 12px;}
.veSpecifier .veVariableName {padding-top: 3px;}
.veSpecifier .veDimensionFont {font-style: italic; color: #9A9A9A;}
.veSpecifier .scroller::-webkit-scrollbar-track {background-color: white;}
.veSpecifier .scroller::-webkit-scrollbar-corner {background-color: white;}
.veSpecifier .veTable .topRowHeaderWrapper {border: none; background-color: #F8F9FA;}
.veSpecifier .mw_type_ListBase.showCellBorders,.veSpecifier .veTable .topHeaderWrapper,.veSpecifier .veTable .bottomRowHeaderWrapper,.veSpecifier .veTable .verticalScrollSpacer,.veSpecifier .veTable .horizontalScrollSpacer {border: none;}
.veSpecifier .veTable .dataScrollerNode {border: 1px solid #BFBFBF;}
.veSpecifier .veTable .columnHeaderNode,.veSpecifier .veTable .rowHeaderNode,.veSpecifier .veTable .dataBody {font-family: Arial; font-size: 13px;}
.veSpecifier .veTable .columnHeaderNode,.veSpecifier .veTable .rowHeaderNode {color: #7F7F7F;}
.veSpecifier .veTable .dataBody {color: #000000;}
.veSpecifier .veTable .columnHeaderNode .cell .drag,.veSpecifier .veTable .columnHeaderNode .cell .header,.veSpecifier .veTable .topHeaderWrapper,.veSpecifier .veTable .bottomRowHeaderWrapper {background-color: #F8F9FA;}
.veSpecifier .veTable .columnHeaderNode .cell .dragBorder {border-right: 1px solid #F8F9FA;}
.veSpecifier .veTable .rowHeaderNode .cell {padding-top: 3px; text-align: center; border-bottom: 1px solid #F8F9FA;}
.veSpecifier .veTable .dataBody .cell .plainText {text-align: right;}
.veSpecifier .veTable .dataBody .row .cell {border-bottom: 1px solid #E9E9E9; border-right: 1px solid #E9E9E9;}
.embeddedOutputsVariableElement {font-family: Consolas, Inconsolata, Menlo, monospace; font-size: 12px; white-space: pre-wrap; word-wrap: break-word; min-height: 18px; max-height: 250px; overflow: auto;}
.variableElement {}
.embeddedOutputsVariableElement.inlineElement {}
.inlineElement .variableElement {}
.variableValue { width: 100% !important; }
.embeddedOutputsMatrixElement {min-height: 18px; box-sizing: border-box; font-family: Consolas, Inconsolata, Menlo, monospace; font-size: 12px;}
.matrixElement .variableValue {white-space: pre; display: inline-block; vertical-align: top; overflow: hidden;}
.embeddedOutputsMatrixElement.inlineElement {}
.embeddedOutputsMatrixElement.inlineElement .topHeaderWrapper {display: none;}
.embeddedOutputsMatrixElement.inlineElement .veTable .body {padding-top: 0 !important; max-height: 100px;}
.embeddedOutputsMatrixElement.inlineElement .veVariableName {padding-top: 0;}
.inlineElement .matrixElement {max-height: 300px;}
.embeddedOutputsMatrixElement .matrixElement .valueContainer {white-space: nowrap; padding-top: 10px; margin-bottom: 3px;}
.embeddedOutputsMatrixElement .matrixElement .valueContainer .horizontalEllipsis.hide,.embeddedOutputsMatrixElement .matrixElement .verticalEllipsis.hide {display: none;}
.embeddedOutputsMatrixElement .matrixElement .valueContainer .horizontalEllipsis {margin-bottom: -3px;}
.matrixElement { max-height: none !important; }
.dijitTooltipDialog .dijitTooltipContainer .dijitTooltipContents .alertPlugin-alertMessage {min-width: 12px; max-width: 400px; max-height: 300px; overflow: auto;}
.dijitTooltipDialog .alertPlugin-alertMessage::-webkit-scrollbar {width: 11px; height: 11px;}
.dijitTooltipDialog .alertPlugin-alertMessage::-webkit-scrollbar-track {background-color: rgba(0, 0, 0, 0);}
.dijitTooltipDialog .alertPlugin-alertMessage::-webkit-scrollbar-corner {background-color: rgba(0, 0, 0, 0);}
.dijitTooltipDialog .alertPlugin-alertMessage::-webkit-scrollbar-thumb {border-radius: 7px; background-color: rgba(0, 0, 0, 0.1); border: 2px solid rgba(0, 0, 0, 0); background-clip: padding-box;}
.dijitTooltipDialog .alertPlugin-alertMessage::-webkit-scrollbar-thumb:hover {background-color: rgba(0, 0, 0, 0.2);}
.dijitTooltipDialog .alertPlugin-alertMessage::-webkit-scrollbar-thumb {background-color: rgba(0, 0, 0, 0);}
.dijitTooltipDialog .alertPlugin-alertMessage:hover::-webkit-scrollbar-thumb {background-color: rgba(0, 0, 0, 0.1);}
.dijitTooltipDialog .alertPlugin-alertMessage:hover::-webkit-scrollbar-thumb:hover {background-color: rgba(0, 0, 0, 0.2);}
.alertPlugin-alertLine {position: absolute; display: initial; width: 40px; text-align: right; cursor: text;}
.alertPlugin-onTextLine {visibility: hidden;}
.alertPlugin-hasTooltip .alertPlugin-warningImg,.alertPlugin-hasTooltip .alertPlugin-errorImg {cursor: pointer;}
.alertPlugin-isStale {-webkit-filter: opacity(0.4) grayscale(80%); filter: opacity(0.4) grayscale(80%);}
.alertPlugin-alertLine .alertPlugin-errorElement {display: inline-block; margin-right: 4px;}
.alertPlugin-errorImg {position: relative; display: inline-block; background-color: rgb(204, 55, 41); width: 14px; height: 14px; margin-top: 1px; -webkit-border-radius: 7px;}
.alertPlugin-alertLine .alertPlugin-warningElement {display: inline-block; margin-right: 3px;}
.alertPlugin-warningImg {position: relative; display: inline-block; width: 16px; height: 15px; overflow: hidden;}
.diagnosticMessage-wrapper {font-family: Consolas, Inconsolata, Menlo, monospace; font-size: 12px;}
.diagnosticMessage-wrapper.diagnosticMessage-warningType {color: rgb(255,100,0);}
.diagnosticMessage-wrapper.diagnosticMessage-warningType a {color: rgb(255,100,0); text-decoration: underline;}
.diagnosticMessage-wrapper.diagnosticMessage-errorType {color: rgb(230,0,0);}
.diagnosticMessage-wrapper.diagnosticMessage-errorType a {color: rgb(230,0,0); text-decoration: underline;}
.diagnosticMessage-wrapper .diagnosticMessage-messagePart {white-space: pre-wrap;}
.diagnosticMessage-wrapper .diagnosticMessage-stackPart {white-space: pre;}
.embeddedOutputsWarningElement{min-height: 18px; max-height: 250px; overflow: auto;}
.embeddedOutputsWarningElement.inlineElement {}
.embeddedOutputsErrorElement {min-height: 18px; max-height: 250px; overflow: auto;}
.embeddedOutputsErrorElement.inlineElement {}
.alertPlugin-warningImg {background-image: url()}
.alertPlugin-errorImg {background-image: url()}
</style></head><body><div class = "content"><div class = 'SectionBlock containment active'><h1 class = "S1"><span class = "S2">实用计算方法实验三——龙格库塔法解一阶常微分方程</span></h1><p class = "S3"><span class = "S2">姓名：林国瑞</span></p><p class = "S3"><span class = "S2">学号：9151010F0118</span></p><div class = 'LineNodeBlock contiguous'><div class = 'inlineWrapper'><p class = "S5 lineNode"><span class = "S6">%已知一阶导数 龙格库塔法</span></p></div><div class = 'inlineWrapper'><p class = "S5 lineNode"><span class = "S6">%遇到角度注意是弧度制还是角度制，matlab中三角函数采用弧度制</span></p></div><div class = 'inlineWrapper'><p class = "S5 lineNode"><span class = "S7">clear</span></p></div><div class = 'inlineWrapper'><p class = "S5 lineNode"><span class = "S7">clc</span></p></div><div class = 'inlineWrapper'><p class = "S5 lineNode"><span class = "S7">x0 = 0;</span></p></div><div class = 'inlineWrapper'><p class = "S5 lineNode"><span class = "S7">xn = 10;</span></p></div><div class = 'inlineWrapper'><p class = "S5 lineNode"><span class = "S8">f = </span><span class = "S8">inline</span><span class = "S8">(</span><span class = "S9">'cos(x)' </span><span class = "S8">, </span><span class = "S9">'x' </span><span class = "S8">, </span><span class = "S9">'y'</span><span class = "S7">) ;</span></p></div><div class = 'inlineWrapper'><p class = "S5 lineNode"><span class = "S7">h = 0.2;</span></p></div><div class = 'inlineWrapper'><p class = "S5 lineNode"><span class = "S7">y0= 0;</span></p></div><div class = 'inlineWrapper'><p class = "S5 lineNode"><span class = "S8">x = x0:h:xn ;  </span><span class = "S6">% ==  计算节点 ==</span></p></div><div class = 'inlineWrapper'><p class = "S5 lineNode"><span class = "S7">y(1) = y0 ;</span></p></div><div class = 'inlineWrapper'><p class = "S5 lineNode"><span class = "S8">N = length(x) ;  </span><span class = "S6">% ==  节点数 ==</span></p></div><div class = 'inlineWrapper'><p class = "S5 lineNode"><span class = "S6">% 参数初始化，以下是通用参数 ===课本（1）</span></p></div><div class = 'inlineWrapper'><p class = "S5 lineNode"><span class = "S7">c = [1/6 1/3 1/3 1/6] ;</span></p></div><div class = 'inlineWrapper'><p class = "S5 lineNode"><span class = "S7">r = [0.5 0.5 1] ;</span></p></div><div class = 'inlineWrapper'><p class = "S5 lineNode"><span class = "S7">u = [0.5 0 0.5 0 0 1] ;</span></p></div><div class = 'inlineWrapper'><p class = "S5 lineNode"><span class = "S7"></span></p></div><div class = 'inlineWrapper'><p class = "S5 lineNode"><span class = "S10">for </span><span class = "S8">k = 1:N-1  </span><span class = "S6">% ==  以下就直接按书本公式写的 ==</span></p></div><div class = 'inlineWrapper'><p class = "S5 lineNode"><span class = "S7">    kk(1) = f( x(k) , y(k) ) ;</span></p></div><div class = 'inlineWrapper'><p class = "S5 lineNode"><span class = "S7">    kk(2) = f( x(k)+r(1)*h , y(k) + u(1)*h*kk(1) ) ;</span></p></div><div class = 'inlineWrapper'><p class = "S5 lineNode"><span class = "S7">    kk(3) = f( x(k)+r(2)*h , y(k) + u(2)*h*kk(1) + u(3)*h*kk(2) ) ;</span></p></div><div class = 'inlineWrapper'><p class = "S5 lineNode"><span class = "S7">    kk(4)  = f( x(k)+r(3)*h  , y(k)  + u(4)*h*kk(1)  + u(5)*h*kk(2)  + u(6)*h*kk(3) ) ;</span></p></div><div class = 'inlineWrapper'><p class = "S5 lineNode"><span class = "S8">    </span><span class = "S8">y</span><span class = "S7">(k+1)  = y(k)  + h*  ( c(1)*kk(1)  + c(2)*kk(2)  +  c(3)*kk(3)  + c(4)*kk(4) ) ;</span></p></div><div class = 'inlineWrapper'><p class = "S5 lineNode"><span class = "S11">end</span></p></div><div class = 'inlineWrapper'><p class = "S5 lineNode"><span class = "S6">%if (0 == nargout)</span></p></div><div class = 'inlineWrapper'><p class = "S5 lineNode"><span class = "S10">for </span><span class = "S7">k = 1:N</span></p></div><div class = 'inlineWrapper'><p class = "S5 lineNode"><span class = "S8">    </span><span class = "S8">y2</span><span class = "S8">(k)=sin(x(k));</span><span class = "S6">%y2为解析解,y为数值解</span></p></div><div class = 'inlineWrapper'><p class = "S5 lineNode"><span class = "S8">    fprintf( </span><span class = "S9">'x: %f \t y: %f  y2: %f w :%f\n' </span><span class = "S7">, x(k) , y(k), y2(k), y(k)-(y2(k)) ) ;</span></p></div><div class = 'inlineWrapper'><p class = "S5 lineNode"><span class = "S11">end</span></p></div></div><p class = "S12"><span class = "S2">x: 0.000000 	 y: 0.000000  y2: 0.000000 w :0.000000</span></p><p class = "S3"><span class = "S2">x: 0.200000 	 y: 0.198669  y2: 0.198669 w :0.000000</span></p><p class = "S3"><span class = "S2">x: 0.400000 	 y: 0.389419  y2: 0.389418 w :0.000000</span></p><p class = "S3"><span class = "S2">x: 0.600000 	 y: 0.564643  y2: 0.564642 w :0.000000</span></p><p class = "S3"><span class = "S2">x: 0.800000 	 y: 0.717356  y2: 0.717356 w :0.000000</span></p><p class = "S3"><span class = "S2">x: 1.000000 	 y: 0.841471  y2: 0.841471 w :0.000000</span></p><p class = "S3"><span class = "S2">x: 1.200000 	 y: 0.932040  y2: 0.932039 w :0.000001</span></p><p class = "S3"><span class = "S2">x: 1.400000 	 y: 0.985450  y2: 0.985450 w :0.000001</span></p><p class = "S3"><span class = "S2">x: 1.600000 	 y: 0.999574  y2: 0.999574 w :0.000001</span></p><p class = "S3"><span class = "S2">x: 1.800000 	 y: 0.973848  y2: 0.973848 w :0.000001</span></p><p class = "S3"><span class = "S2">x: 2.000000 	 y: 0.909298  y2: 0.909297 w :0.000001</span></p><p class = "S3"><span class = "S2">x: 2.200000 	 y: 0.808497  y2: 0.808496 w :0.000000</span></p><p class = "S3"><span class = "S2">x: 2.400000 	 y: 0.675464  y2: 0.675463 w :0.000000</span></p><p class = "S3"><span class = "S2">x: 2.600000 	 y: 0.515502  y2: 0.515501 w :0.000000</span></p><p class = "S3"><span class = "S2">x: 2.800000 	 y: 0.334988  y2: 0.334988 w :0.000000</span></p><p class = "S3"><span class = "S2">x: 3.000000 	 y: 0.141120  y2: 0.141120 w :0.000000</span></p><p class = "S3"><span class = "S2">x: 3.200000 	 y: -0.058374  y2: -0.058374 w :-0.000000</span></p><p class = "S3"><span class = "S2">x: 3.400000 	 y: -0.255541  y2: -0.255541 w :-0.000000</span></p><p class = "S3"><span class = "S2">x: 3.600000 	 y: -0.442521  y2: -0.442520 w :-0.000000</span></p><p class = "S3"><span class = "S2">x: 3.800000 	 y: -0.611858  y2: -0.611858 w :-0.000000</span></p><p class = "S3"><span class = "S2">x: 4.000000 	 y: -0.756803  y2: -0.756802 w :-0.000000</span></p><p class = "S3"><span class = "S2">x: 4.200000 	 y: -0.871576  y2: -0.871576 w :-0.000000</span></p><p class = "S3"><span class = "S2">x: 4.400000 	 y: -0.951603  y2: -0.951602 w :-0.000001</span></p><p class = "S3"><span class = "S2">x: 4.600000 	 y: -0.993692  y2: -0.993691 w :-0.000001</span></p><p class = "S3"><span class = "S2">x: 4.800000 	 y: -0.996165  y2: -0.996165 w :-0.000001</span></p><p class = "S3"><span class = "S2">x: 5.000000 	 y: -0.958925  y2: -0.958924 w :-0.000001</span></p><p class = "S3"><span class = "S2">x: 5.200000 	 y: -0.883455  y2: -0.883455 w :-0.000000</span></p><p class = "S3"><span class = "S2">x: 5.400000 	 y: -0.772765  y2: -0.772764 w :-0.000000</span></p><p class = "S3"><span class = "S2">x: 5.600000 	 y: -0.631267  y2: -0.631267 w :-0.000000</span></p><p class = "S3"><span class = "S2">x: 5.800000 	 y: -0.464602  y2: -0.464602 w :-0.000000</span></p><p class = "S3"><span class = "S2">x: 6.000000 	 y: -0.279416  y2: -0.279415 w :-0.000000</span></p><p class = "S3"><span class = "S2">x: 6.200000 	 y: -0.083089  y2: -0.083089 w :-0.000000</span></p><p class = "S3"><span class = "S2">x: 6.400000 	 y: 0.116549  y2: 0.116549 w :0.000000</span></p><p class = "S3"><span class = "S2">x: 6.600000 	 y: 0.311542  y2: 0.311541 w :0.000000</span></p><p class = "S3"><span class = "S2">x: 6.800000 	 y: 0.494114  y2: 0.494113 w :0.000000</span></p><p class = "S3"><span class = "S2">x: 7.000000 	 y: 0.656987  y2: 0.656987 w :0.000000</span></p><p class = "S3"><span class = "S2">x: 7.200000 	 y: 0.793668  y2: 0.793668 w :0.000000</span></p><p class = "S3"><span class = "S2">x: 7.400000 	 y: 0.898709  y2: 0.898708 w :0.000000</span></p><p class = "S3"><span class = "S2">x: 7.600000 	 y: 0.967920  y2: 0.967920 w :0.000001</span></p><p class = "S3"><span class = "S2">x: 7.800000 	 y: 0.998544  y2: 0.998543 w :0.000001</span></p><p class = "S3"><span class = "S2">x: 8.000000 	 y: 0.989359  y2: 0.989358 w :0.000001</span></p><p class = "S3"><span class = "S2">x: 8.200000 	 y: 0.940731  y2: 0.940731 w :0.000001</span></p><p class = "S3"><span class = "S2">x: 8.400000 	 y: 0.854599  y2: 0.854599 w :0.000000</span></p><p class = "S3"><span class = "S2">x: 8.600000 	 y: 0.734398  y2: 0.734397 w :0.000000</span></p><p class = "S3"><span class = "S2">x: 8.800000 	 y: 0.584918  y2: 0.584917 w :0.000000</span></p><p class = "S3"><span class = "S2">x: 9.000000 	 y: 0.412119  y2: 0.412118 w :0.000000</span></p><p class = "S3"><span class = "S2">x: 9.200000 	 y: 0.222890  y2: 0.222890 w :0.000000</span></p><p class = "S3"><span class = "S2">x: 9.400000 	 y: 0.024775  y2: 0.024775 w :0.000000</span></p><p class = "S3"><span class = "S2">x: 9.600000 	 y: -0.174327  y2: -0.174327 w :-0.000000</span></p><p class = "S3"><span class = "S2">x: 9.800000 	 y: -0.366479  y2: -0.366479 w :-0.000000</span></p><p class = "S3"><span class = "S2">x: 10.000000 	 y: -0.544021  y2: -0.544021 w :-0.000000</span></p><div class = 'LineNodeBlock contiguous'><div class = 'inlineWrapper'><p class = "S5 lineNode"><span class = "S6">%elseif (1 == nargout)</span></p></div><div class = 'inlineWrapper'><p class = "S5 lineNode"><span class = "S7">plot(x,y)</span></p></div><div class = 'inlineWrapper outputs'><p class = "S5 lineNode"><span class = "S8">grid </span><span class = "S14">on</span></p><div class="outputParagraph"><div class="inlineElement embeddedOutputsFigure" style="max-height: 800px; width: 716px;"><div class="figureElement"><img class="figureImage" draggable="false" src=""></div></div></div></div></div></div></div>
<!-- 
##### SOURCE BEGIN #####
%% 实用计算方法实验三——龙格库塔法解一阶常微分方程
% 姓名：林国瑞
% 
% 学号：9151010F0118

%已知一阶导数 龙格库塔法
%遇到角度注意是弧度制还是角度制，matlab中三角函数采用弧度制
clear
clc
x0 = 0;
xn = 10;
f = inline('cos(x)' , 'x' , 'y') ;
h = 0.2;
y0= 0;
x = x0:h:xn ;  % ==  计算节点 ==
y(1) = y0 ;
N = length(x) ;  % ==  节点数 ==
% 参数初始化，以下是通用参数 ===课本（1）
c = [1/6 1/3 1/3 1/6] ;
r = [0.5 0.5 1] ;
u = [0.5 0 0.5 0 0 1] ;

for k = 1:N-1  % ==  以下就直接按书本公式写的 ==
    kk(1) = f( x(k) , y(k) ) ;
    kk(2) = f( x(k)+r(1)*h , y(k) + u(1)*h*kk(1) ) ;
    kk(3) = f( x(k)+r(2)*h , y(k) + u(2)*h*kk(1) + u(3)*h*kk(2) ) ;
    kk(4)  = f( x(k)+r(3)*h  , y(k)  + u(4)*h*kk(1)  + u(5)*h*kk(2)  + u(6)*h*kk(3) ) ;
    y(k+1)  = y(k)  + h*  ( c(1)*kk(1)  + c(2)*kk(2)  +  c(3)*kk(3)  + c(4)*kk(4) ) ;
end
%if (0 == nargout)
for k = 1:N
    y2(k)=sin(x(k));%y2为解析解,y为数值解
    fprintf( 'x: %f \t y: %f  y2: %f w :%f\n' , x(k) , y(k), y2(k), y(k)-(y2(k)) ) ;
end
%% 
% x: 0.000000 	 y: 0.000000  y2: 0.000000 w :0.000000
% 
% x: 0.200000 	 y: 0.198669  y2: 0.198669 w :0.000000
% 
% x: 0.400000 	 y: 0.389419  y2: 0.389418 w :0.000000
% 
% x: 0.600000 	 y: 0.564643  y2: 0.564642 w :0.000000
% 
% x: 0.800000 	 y: 0.717356  y2: 0.717356 w :0.000000
% 
% x: 1.000000 	 y: 0.841471  y2: 0.841471 w :0.000000
% 
% x: 1.200000 	 y: 0.932040  y2: 0.932039 w :0.000001
% 
% x: 1.400000 	 y: 0.985450  y2: 0.985450 w :0.000001
% 
% x: 1.600000 	 y: 0.999574  y2: 0.999574 w :0.000001
% 
% x: 1.800000 	 y: 0.973848  y2: 0.973848 w :0.000001
% 
% x: 2.000000 	 y: 0.909298  y2: 0.909297 w :0.000001
% 
% x: 2.200000 	 y: 0.808497  y2: 0.808496 w :0.000000
% 
% x: 2.400000 	 y: 0.675464  y2: 0.675463 w :0.000000
% 
% x: 2.600000 	 y: 0.515502  y2: 0.515501 w :0.000000
% 
% x: 2.800000 	 y: 0.334988  y2: 0.334988 w :0.000000
% 
% x: 3.000000 	 y: 0.141120  y2: 0.141120 w :0.000000
% 
% x: 3.200000 	 y: -0.058374  y2: -0.058374 w :-0.000000
% 
% x: 3.400000 	 y: -0.255541  y2: -0.255541 w :-0.000000
% 
% x: 3.600000 	 y: -0.442521  y2: -0.442520 w :-0.000000
% 
% x: 3.800000 	 y: -0.611858  y2: -0.611858 w :-0.000000
% 
% x: 4.000000 	 y: -0.756803  y2: -0.756802 w :-0.000000
% 
% x: 4.200000 	 y: -0.871576  y2: -0.871576 w :-0.000000
% 
% x: 4.400000 	 y: -0.951603  y2: -0.951602 w :-0.000001
% 
% x: 4.600000 	 y: -0.993692  y2: -0.993691 w :-0.000001
% 
% x: 4.800000 	 y: -0.996165  y2: -0.996165 w :-0.000001
% 
% x: 5.000000 	 y: -0.958925  y2: -0.958924 w :-0.000001
% 
% x: 5.200000 	 y: -0.883455  y2: -0.883455 w :-0.000000
% 
% x: 5.400000 	 y: -0.772765  y2: -0.772764 w :-0.000000
% 
% x: 5.600000 	 y: -0.631267  y2: -0.631267 w :-0.000000
% 
% x: 5.800000 	 y: -0.464602  y2: -0.464602 w :-0.000000
% 
% x: 6.000000 	 y: -0.279416  y2: -0.279415 w :-0.000000
% 
% x: 6.200000 	 y: -0.083089  y2: -0.083089 w :-0.000000
% 
% x: 6.400000 	 y: 0.116549  y2: 0.116549 w :0.000000
% 
% x: 6.600000 	 y: 0.311542  y2: 0.311541 w :0.000000
% 
% x: 6.800000 	 y: 0.494114  y2: 0.494113 w :0.000000
% 
% x: 7.000000 	 y: 0.656987  y2: 0.656987 w :0.000000
% 
% x: 7.200000 	 y: 0.793668  y2: 0.793668 w :0.000000
% 
% x: 7.400000 	 y: 0.898709  y2: 0.898708 w :0.000000
% 
% x: 7.600000 	 y: 0.967920  y2: 0.967920 w :0.000001
% 
% x: 7.800000 	 y: 0.998544  y2: 0.998543 w :0.000001
% 
% x: 8.000000 	 y: 0.989359  y2: 0.989358 w :0.000001
% 
% x: 8.200000 	 y: 0.940731  y2: 0.940731 w :0.000001
% 
% x: 8.400000 	 y: 0.854599  y2: 0.854599 w :0.000000
% 
% x: 8.600000 	 y: 0.734398  y2: 0.734397 w :0.000000
% 
% x: 8.800000 	 y: 0.584918  y2: 0.584917 w :0.000000
% 
% x: 9.000000 	 y: 0.412119  y2: 0.412118 w :0.000000
% 
% x: 9.200000 	 y: 0.222890  y2: 0.222890 w :0.000000
% 
% x: 9.400000 	 y: 0.024775  y2: 0.024775 w :0.000000
% 
% x: 9.600000 	 y: -0.174327  y2: -0.174327 w :-0.000000
% 
% x: 9.800000 	 y: -0.366479  y2: -0.366479 w :-0.000000
% 
% x: 10.000000 	 y: -0.544021  y2: -0.544021 w :-0.000000

%elseif (1 == nargout)
plot(x,y)
grid on
##### SOURCE END #####
--></body></html>